<!DOCTYPE html>
<html>

<head>
  <title>Users Settings - AIL</title>
	<link rel="icon" href="{{ url_for('static', filename='image/ail-icon.png') }}">

  <!-- Core CSS -->
	<link href="{{ url_for('static', filename='css/bootstrap4.min.css') }}" rel="stylesheet">
	<link href="{{ url_for('static', filename='css/font-awesome.min.css') }}" rel="stylesheet">
	<link href="{{ url_for('static', filename='css/dataTables.bootstrap.min.css') }}" rel="stylesheet">

  <!-- JS -->
	<script src="{{ url_for('static', filename='js/jquery.js')}}"></script>
	<script src="{{ url_for('static', filename='js/popper.min.js')}}"></script>
	<script src="{{ url_for('static', filename='js/bootstrap4.min.js')}}"></script>
	<script src="{{ url_for('static', filename='js/jquery.dataTables.min.js')}}"></script>
	<script src="{{ url_for('static', filename='js/dataTables.bootstrap.min.js')}}"></script>

</head>
<body>

{% include 'nav_bar.html' %}

	<div class="container-fluid">
		<div class="row">
            {% include 'settings/menu_sidebar.html' %}
			<div class="col-12 col-lg-10" id="core_content">

                <h3>AIL Users:</h3>
                <span>Logged <span class="badge badge-success">{{ meta['logged'] }}</span></span>
                <span>Active <span class="badge badge-primary">{{ meta['active'] }}</span></span>
                <table id="tableusers" class="table table-hover table-striped">
                    <thead class="thead-dark">
                    <tr>
                        <th>User</th>
                        <th>Org</th>
                        <th>Last Edit</th>
                        <th>Last Login</th>
                        <th>Last Seen</th>
                        <th>Role</th>
                        <th>Last API Access</th>
                        <th>2FA</th>
                        <th>Actions</th>
                    </tr>
                    </thead>
                    <tbody id="tbody_last_crawled">
                    {% for user in meta['users'] %}
                        <tr>
                            <td>
                                <a href="{{ url_for('settings_b.user_view', user_id=user['id']) }}">
                                    {{user['id']}}
                                </a>
                                {% if user['is_disabled'] %}
                                    <span class="badge badge-danger"><b>Disabled</b></span>
                                {% endif %}
                            </td>
                            <td>
                                {{ user['org_name'] }}<br>
                                {{user['org']}}
                            </td>
                            <td>{{user['last_edit']}}</td>
                            <td>
                                {% if user['last_login'] %}
                                    {{user['last_login']}}
                                {% else %}-{% endif %}
                            {{ meta['is_logged'] }}
                                {% if user['is_logged'] %}
                                    <i class="fas fa-plug text-success"></i>
                                    <a class="btn btn-outline-danger px-1 py-0" href="{{ url_for('settings_b.user_logout', user_id=user['id']) }}">
                                        <i class="fas fa-sign-out-alt"></i>
                                    </a>
                                {% endif %}
                            </td>
                            <td>{% if user['last_seen'] %}{{user['last_seen']}}{% else %}-{% endif %}</td>
                            <td>{{user['role']}}</td>
                            <td>
                                {% if user['last_seen_api'] %}{{user['last_seen_api']}}{% else %}-{% endif %}
                                {% if user['is_disabled'] %}
                                    <br>
                                    <span class="badge badge-danger"><b>Disabled</b></span>
                                {% endif %}
                            </td>
                            <td>
                                {% if user['2fa'] %}
                                    {% if user['otp_setup'] %}
                                        <span class="badge badge-success" style="font-size: 1.0rem;"><b>YES</b></span>
                                        <a class="btn btn-outline-danger px-1 py-0" href="{{ url_for('settings_b.user_otp_reset', user_id=user['id']) }}">
                                            <i class="fas fa-random"></i> Reset
                                        </a>
                                    {% else %}
                                        <span class="badge badge-warning" style="font-size: 1.0rem;"><b>ENFORCED</b></span>
                                    {% endif %}
                                    <a class="btn btn-outline-danger px-1 py-0" href="{{ url_for('settings_b.user_otp_disable', user_id=user['id']) }}">
                                        <i class="fas fa-times"></i>
                                    </a>
                                {% else %}
                                    <span class="badge badge-danger" style="font-size: 1.0rem;"><b>NO</b></span>
                                    <a class="btn btn-outline-success px-1 py-0" href="{{ url_for('settings_b.user_otp_enable', user_id=user['id']) }}">
                                        <i class="fas fa-plus"></i>
                                    </a>
                                {% endif %}

                            </td>
                            <td>
                                <div class="d-flex justify-content-start">
                                    <a class="btn btn-outline-primary ml-3 px-1 py-0" href="{{ url_for('settings_b.edit_user', user_id=user['id']) }}">
                                        <i class="fas fa-pencil-alt"></i>
                                    </a>
                                    {% if user['is_disabled'] %}
                                        <a class="btn btn-outline-success ml-3 px-1 py-0" href="{{ url_for('settings_b.user_enable', user_id=user['id']) }}">
                                            <i class="fas fa-user-check"></i>
                                        </a>
                                    {% else %}
                                        <a class="btn btn-outline-danger ml-3 px-1 py-0" href="{{ url_for('settings_b.user_disable', user_id=user['id']) }}">
                                            <i class="fas fa-user-slash"></i>
                                        </a>
                                    {% endif %}
                                    <a class="btn btn-outline-danger ml-3 px-1 py-0" href="{{ url_for('settings_b.delete_user', user_id=user['id']) }}">
                                        <i class="fas fa-trash-alt"></i>
                                    </a>
                                </div>
                            </td>
                        </tr>
                    {% endfor %}
                    </tbody>
                </table>

                <a class="btn btn-danger my-4" href="{{ url_for('settings_b.users_logout') }}">
                    <i class="fas fa-sign-out-alt"></i> Logout All Users
                </a>

    	    </div>
		</div>
	</div>
</body>

<script>
$(document).ready(function(){
    $("#nav_users_list").addClass("active");
	$("#nav_user_management").removeClass("text-muted");
    $('#tableusers').DataTable({
        "aLengthMenu": [[5, 10, 15, -1], [5, 10, 15, "All"]],
        "iDisplayLength": 10,
        "order": [[ 4, "desc" ]]
    });
});

function toggle_sidebar(){
	if($('#nav_menu').is(':visible')){
		$('#nav_menu').hide();
		$('#side_menu').removeClass('border-right')
		$('#side_menu').removeClass('col-lg-2')
		$('#core_content').removeClass('col-lg-10')
	}else{
		$('#nav_menu').show();
		$('#side_menu').addClass('border-right')
		$('#side_menu').addClass('col-lg-2')
		$('#core_content').addClass('col-lg-10')
	}
}
</script>

</html>
